<?
#include "Grid.class.php";
class GridPresenter{
	
	

	public static function GetHTMLTable($matrix, $has_header = true){
		$html = "<table>\n";
					 
		foreach($matrix as $key => $rows){	

			if($has_header && $key ==0) $html .= "<thead>";

			$html .= "<tr>\n";			
			
			foreach($rows as $column){
				if($key%2 == 0)		$html .= "<td>".$column."</td>";
				else				$html .= "<td class=\"selectedRow\">".$column."</td>";
			}
				
			$html .= "\n</tr>\n";
			if($has_header && $key ==0) $html .= "</thead>";
		}
		$html .= "</table>\n";	
		return $html;
	 } #GetHTMLTable
	 
	 public static function GetHTMLReport($matrix, $has_header = true){
	 
		$nrows = count($matrix);
		$ncols = count($matrix[0]);

		$html = "<table>\n";
					 
		foreach($matrix as $rowsIndex => $rows){	
			if($has_header && $rowsIndex ==0) $html .= "<thead>";
			
			if($rowsIndex== $nrows-1)
				$html .= "<tr class=\"totals\">\n";			
			else
				$html .= "<tr>\n";			
			
			foreach($rows as $colsIndex => $column){
				if($rowsIndex%2 == 0){		
#					if($colsIndex == $ncols-1 || $rowsIndex == $nrows-1)	
					if($colsIndex == $ncols-1 || $colsIndex == $ncols-2 || $rowsIndex == $nrows-1)	
						$html .= "<td class=\"totals\">".$column."</td>";
					else
						$html .= "<td>".$column."</td>";				
				}else{
#					if($colsIndex == $ncols-1 || $rowsIndex == $nrows-1)	
					if($colsIndex == $ncols-1 || $colsIndex == $ncols-2 || $rowsIndex == $nrows-1)	
						$html .= "<td class=\"totals\">".$column."</td>";
					else
						$html .= "<td class=\"selectedRow\">".$column."</td>";	
				}			
				
				
			}#foreach colsIndex
			$html .= "\n</tr>\n";
			if($has_header && $rowsIndex ==0) $html .= "</thead>";
		}
		$html .= "</table>\n";	
		return $html;
	 } #GetHTMLReport
}#GridPresenter

/*
$g = new Grid();
$g->grid[0][0] = 1;
$g->grid[0][1] = 2;
$g->grid[1][0] = 3;
$g->grid[1][1] = 4;

$g->AppendRowTotal($g->grid[0]);
$g->AppendRowTotal($g->grid[1]);

$g->AppendColumnTotal(0);
$g->AppendColumnTotal(1);
$g->AppendColumnTotal(2);

#GridPresenter::SetHeader(array("toma1", "toma2", "total"));
#print_r(GridPresenter::$header);
#echo GridPresenter::GetHTMLHeader(GridPresenter::$header);
echo GridPresenter::GetHTMLTable($g->grid);

#$g->walk();
*/
?>
